/*This is the Replication code for our Health at the Margins: How Historical Ethnic Borders SHape Contemporary Outcomes paper

Prepared by: Adu Sarfo Emmanuel and Tweneboah Rabbi
*/

/*Set working directory*/
cd "../replication"

/*Load data*/
use "ASE_TR_HM_data.dta", clear



global geog " grid_lat grid_lon mean_elevation"

global climate "precipitaion temperature"

global devt "night_luminosity_avg"

global pollution "particle carbon air_poll"


global minearal "mineral_deposits_bd viol_event_acled_bd battle_acled_bd rebel_acled_bd local_conf_mosc_acled_bd"

/**********************************************************************/
/*             The Main Tables in Our Paper                           */
/*                                                                    */
/**********************************************************************/


/*Table 1*/

/*Column 1*/
reghdfe log_unimproved_sanitation atborder, noabsorb cl(grid_id)      
   
/*Column 2*/   
reghdfe log_unimproved_sanitation atborder, absorb(cid)	cl(grid_id)

/*Column 3*/
reghdfe log_unimproved_sanitation atborder, absorb(cid eth_fe)	cl(grid_id)

/*Column 4*/
reghdfe log_unimproved_sanitation atborder ${geog}, absorb(cid eth_fe)	cl(grid_id)


/*Column 5*/
reghdfe log_unimproved_sanitation atborder ${geog} ${climate}, absorb(cid eth_fe)	cl(grid_id)

/*Column 6*/
reghdfe log_open_defecation atborder ${geog} ${climate}, absorb(cid eth_fe)	cl(grid_id)

/*Column 7*/
reghdfe log_bad_water atborder ${geog} ${climate}, absorb(cid eth_fe)	cl(grid_id)




/*Table 2*/

/*Column 1*/
reghdfe atborder at_vor_border, noabsorb cl(grid_id)


/*Column 2*/
reghdfe atborder at_vor_border, absorb(cid) cl(grid_id)


/*Column 3*/
reghdfe atborder at_vor_border, absorb(cid eth_fe) cl(grid_id)

/*Column 4*/
reghdfe atborder at_vor_border ${geog}, absorb(cid eth_fe) cl(grid_id)


/*Column 5*/
reghdfe atborder at_vor_border ${geog} ${climate}, absorb(cid eth_fe) cl(grid_id)




/*Table 3*/

/*Column 1*/
ivreghdfe log_unimproved_sanitation (atborder= at_vor_border),  cl(grid_id)  first

/*Column 2*/
ivreghdfe log_unimproved_sanitation (atborder= at_vor_border) ${geog} ${climate}, absorb(cid eth_fe) cl(grid_id) first

/*Column 3*/
ivreghdfe log_open_defecation (atborder= at_vor_border), first cl(grid_id)     

/*Column 4*/
ivreghdfe log_open_defecation (atborder= at_vor_border) ${geog} ${climate}, absorb(cid eth_fe) cl(grid_id) first

/*Column 5*/
ivreghdfe log_bad_water (atborder= at_vor_border), first cl(grid_id)   

/*Column 6*/
ivreghdfe log_bad_water (atborder= at_vor_border) ${geog} ${climate}, absorb(cid eth_fe) cl(grid_id) first




/*Table 4*/


/*Column 1*/
reghdfe malaria atborder, noabsorb	cl(grid_id)

/*Column 2*/
reghdfe malaria atborder, absorb(cid)	cl(grid_id)


/*Column 3*/
reghdfe malaria atborder, absorb(cid eth_fe) cl(grid_id)


/*Column 4*/
reghdfe malaria atborder ${geog}, absorb(cid eth_fe) cl(grid_id)


/*Column 5*/
reghdfe malaria atborder ${geog} ${climate}, absorb(cid eth_fe)	cl(grid_id)


/*Column 6*/
ivreghdfe malaria (atborder = at_vor_border) ${geog} ${climate}, absorb(cid eth_fe) cl(grid_id) first


/***************************************************************************************/
/*   Table 5 through 7 contains dhs data and we are not able to share                  */
/***************************************************************************************/



/*Table 8*/
reghdfe health_facility numbord ${geog} ${climate}, absorb(cid eth_fe) cl(grid_id)


reghdfe accessibility_to_cities_2015_v10 numbord ${geog} ${climate}, absorb(cid eth_fe) cl(grid_id)


foreach var of global minearal {
reghdfe log_unimproved_sanitation numbord ${geog} ${climate} `var', absorb(cid eth_fe)	cl(grid_id)
}



/**********************************************************************/
/*    Additional Robustness Tables in Our Appendix File               */
/*                                                                    */
/**********************************************************************/

/*Additional Climatic Control*/
global addclimate "day_temp night_temp"

/*Column 1*/
reghdfe log_unimproved_sanitation atborder ${geog} ${climate} ${addclimate}, absorb(cid eth_fe)	cl(grid_id)


/*Column 2*/
ivreghdfe log_unimproved_sanitation (atborder= at_vor_border) ${geog} ${climate} ${addclimate}, absorb(cid eth_fe) cl(grid_id) first


/*Column 3*/
reghdfe log_open_defecation atborder ${geog} ${climate} ${addclimate}, absorb(cid eth_fe)	cl(grid_id)


/*Column 4*/
ivreghdfe log_open_defecation (atborder= at_vor_border) ${geog} ${climate} ${addclimate}, absorb(cid eth_fe) cl(grid_id) first


/*Column 5*/
reghdfe log_bad_water atborder ${geog} ${climate} ${addclimate}, absorb(cid eth_fe)	cl(grid_id)


/*Column 6*/
ivreghdfe log_bad_water (atborder= at_vor_border) ${geog} ${climate} ${addclimate}, absorb(cid eth_fe) cl(grid_id) first




/*Local Development*/


/*Column 1*/
reghdfe log_unimproved_sanitation atborder ${geog} ${climate} ${devt}, absorb(cid eth_fe)	cl(grid_id)


/*Column 2*/
ivreghdfe log_unimproved_sanitation (atborder= at_vor_border) ${geog} ${climate} ${devt}, absorb(cid eth_fe) cl(grid_id) first


/*Column 3*/
reghdfe log_open_defecation atborder ${geog} ${climate} ${devt}, absorb(cid eth_fe)	cl(grid_id)


/*Column 4*/
ivreghdfe log_open_defecation (atborder= at_vor_border) ${geog} ${climate} ${devt}, absorb(cid eth_fe) cl(grid_id) first


/*Column 5*/
reghdfe log_bad_water atborder ${geog} ${climate} ${devt}, absorb(cid eth_fe)	cl(grid_id)


/*Column 6*/
ivreghdfe log_bad_water (atborder= at_vor_border) ${geog} ${climate} ${devt}, absorb(cid eth_fe) cl(grid_id) first




/*Pollution*/

/*Column 1*/
reghdfe log_unimproved_sanitation atborder ${geog} ${climate} ${pollution}, absorb(cid eth_fe)	cl(grid_id)


/*Column 2*/
ivreghdfe log_unimproved_sanitation (atborder= at_vor_border) ${geog} ${climate} ${pollution}, absorb(cid eth_fe) cl(grid_id) first


/*Column 3*/
reghdfe log_open_defecation atborder ${geog} ${climate} ${pollution}, absorb(cid eth_fe)	cl(grid_id)


/*Column 4*/
ivreghdfe log_open_defecation (atborder= at_vor_border) ${geog} ${climate} ${pollution}, absorb(cid eth_fe) cl(grid_id) first


/*Column 5*/
reghdfe log_bad_water atborder ${geog} ${climate} ${pollution}, absorb(cid eth_fe)	cl(grid_id)


/*Column 6*/
ivreghdfe log_bad_water (atborder= at_vor_border) ${geog} ${climate} ${pollution}, absorb(cid eth_fe) cl(grid_id) first



/*Alternative Ethnic Border Measures and IV Measure*/

/*Table B4*/

/*Column 1*/
reghdfe log_unimproved_sanitation numbord ${geog} ${climate} ${devt}, absorb(cid eth_fe)	cl(grid_id)


/*Column 2*/
reghdfe log_unimproved_sanitation intersection ${geog} ${climate} ${devt}, absorb(cid eth_fe)	cl(grid_id)

/*Column 3*/
reghdfe log_open_defecation numbord ${geog} ${climate} ${devt}, absorb(cid eth_fe)	cl(grid_id)


/*Column 4*/
reghdfe log_open_defecation intersection ${geog} ${climate} ${devt}, absorb(cid eth_fe)	cl(grid_id)


/*Column 5*/
reghdfe log_bad_water numbord ${geog} ${climate} ${devt}, absorb(cid eth_fe)	cl(grid_id)


/*Column 6*/
reghdfe log_bad_water intersection ${geog} ${climate} ${devt}, absorb(cid eth_fe)	cl(grid_id)



/*Table B5*/
 
/*Column 1*/
ivreghdfe log_unimproved_sanitation (atborder= num_vor_bord) ${geog} ${climate}, absorb(cid eth_fe) cl(grid_id) first
   

/*Column 2*/
ivreghdfe log_unimproved_sanitation (atborder= vor_bord_length) ${geog} ${climate}, absorb(cid eth_fe) cl(grid_id) first


/*Column 3*/
ivreghdfe log_open_defecation (atborder= num_vor_bord) ${geog} ${climate}, absorb() cl(grid_id) first
   

/*Column 4*/
ivreghdfe log_open_defecation (atborder= vor_bord_length) ${geog} ${climate}, absorb(cid eth_fe) cl(grid_id) first


/*Column 5*/
ivreghdfe log_bad_water (atborder= num_vor_bord) ${geog} ${climate}, absorb(cid eth_fe) cl(grid_id) first
   

/*Column 6*/
ivreghdfe log_bad_water (atborder= vor_bord_length) ${geog} ${climate}, absorb(cid eth_fe) cl(grid_id) first



/*Table B6*/
/*Column 1*/
ivreghdfe log_unimproved_sanitation (numbord= num_vor_bord) ${geog} ${climate}, absorb(cid eth_fe) cl(grid_id) first
   

/*Column 2*/
ivreghdfe log_unimproved_sanitation (intersection= vor_bord_length) ${geog} ${climate}, absorb(cid eth_fe) cl(grid_id) first


/*Column 3*/
ivreghdfe log_open_defecation (numbord= num_vor_bord) ${geog} ${climate}, absorb(cid eth_fe) cl(grid_id) first
   

/*Column 4*/
ivreghdfe log_open_defecation (intersection= vor_bord_length) ${geog} ${climate}, absorb(cid eth_fe) cl(grid_id) first


/*Column 5*/
ivreghdfe log_bad_water (numbord= num_vor_bord) ${geog} ${climate}, absorb(cid eth_fe) cl(grid_id) first
   

/*Column 6*/
ivreghdfe log_bad_water (intersection= vor_bord_length) ${geog} ${climate}, absorb(cid eth_fe) cl(grid_id) first



/*Alternative Clustering*/


/*Table B7*/
/*Column 1*/
reghdfe log_unimproved_sanitation atborder ${geog} ${climate}, absorb(cid eth_fe)	cl(eth_fe)


/*Column 2*/
ivreghdfe log_unimproved_sanitation (atborder= at_vor_border) ${geog} ${climate}, absorb(cid eth_fe) cl(eth_fe) first


/*Column 3*/
reghdfe log_open_defecation atborder ${geog} ${climate}, absorb(cid eth_fe)	cl(eth_fe)


/*Column 4*/
ivreghdfe log_open_defecation (atborder= at_vor_border) ${geog} ${climate}, absorb(cid eth_fe) cl(eth_fe) first 


/*Column 5*/
reghdfe log_bad_water atborder ${geog} ${climate}, absorb(cid eth_fe)	cl(eth_fe)


/*Column 6*/
ivreghdfe log_bad_water (atborder= at_vor_border) ${geog} ${climate}, absorb(cid eth_fe) cl(eth_fe) first



/*Table B8*/



/*Column 1*/
reghdfe log_unimproved_sanitation atborder ${geog} ${climate}, absorb(cid eth_fe)	cl(prio_id)


/*Column 2*/
ivreghdfe log_unimproved_sanitation (atborder= at_vor_border) ${geog} ${climate}, absorb(cid eth_fe) cl(prio_id) first


/*Column 3*/
reghdfe log_open_defecation atborder ${geog} ${climate}, absorb(cid eth_fe)	cl(prio_id)


/*Column 4*/
ivreghdfe log_open_defecation (atborder= at_vor_border) ${geog} ${climate}, absorb(cid eth_fe) cl(prio_id) first


/*Column 5*/
reghdfe log_bad_water atborder ${geog} ${climate}, absorb(cid eth_fe)	cl(prio_id)


/*Column 6*/
ivreghdfe log_bad_water (atborder= at_vor_border) ${geog} ${climate}, absorb(cid eth_fe) cl(prio_id) first



/*Table B9*/


/*Column 1*/
reghdfe log_unimproved_sanitation atborder ${geog} ${climate}, absorb(cid eth_fe)	cl(cid)


/*Column 2*/
ivreghdfe log_unimproved_sanitation (atborder= at_vor_border) ${geog} ${climate}, absorb(cid eth_fe) cl(cid) first


/*Column 3*/
reghdfe log_open_defecation atborder ${geog} ${climate}, absorb(cid eth_fe)	cl(cid)


/*Column 4*/
ivreghdfe log_open_defecation (atborder= at_vor_border) ${geog} ${climate}, absorb(cid eth_fe) cl(cid) first


/*Column 5*/
reghdfe log_bad_water atborder ${geog} ${climate}, absorb(cid eth_fe)	cl(cid)


/*Column 6*/
ivreghdfe log_bad_water (atborder= at_vor_border) ${geog} ${climate}, absorb(cid eth_fe) cl(cid) first



/*Alternative Health Outcomes*/
/*Table B10*/

reghdfe neonatal_mean atborder ${geog} ${climate}, absorb(cid eth_fe)	cl(grid_id)

reghdfe under5_mort_mean atborder ${geog} ${climate}, absorb(cid eth_fe)	cl(grid_id)

reghdfe gov_hosp atborder ${geog} ${climate}, absorb(cid eth_fe)	cl(grid_id)
